﻿using System;
using System.Collections.Generic;
using System.Text;
using DbHelp;

namespace IotherRis
{
    public class Model_cfg
    {

        string mDbpath;

        public string MDbpath
        {
            get { return mDbpath; }
            set { mDbpath = value; }
        }

        string mDbpath_report;

        public string MDbpath_report
        {
            get { return mDbpath_report; }
            set { mDbpath_report = value; }
        }

        string mPiview_path;

        public string MPiview_path
        {
            get { return mPiview_path; }
            set { mPiview_path = value; }
        }

        string mPiview_arges;

        public string MPiview_arges
        {
            get { return mPiview_arges; }
            set { mPiview_arges = value; }
        }


        string mPiview_arges_dbtype;

        public string MPiview_arges_dbtype
        {
            get { return mPiview_arges_dbtype; }
            set { mPiview_arges_dbtype = value; }
        }

        string mPiview_arges_maxnum;

        public string MPiview_arges_maxnum
        {
            get { return mPiview_arges_maxnum; }
            set { mPiview_arges_maxnum = value; }
        }

        string mPiview_arges_userid;

        public string MPiview_arges_userid
        {
            get { return mPiview_arges_userid; }
            set { mPiview_arges_userid = value; }
        }


        string mPiview_arges_userpwd;

        public string MPiview_arges_userpwd
        {
            get { return mPiview_arges_userpwd; }
            set { mPiview_arges_userpwd = value; }
        }

        string mPiview_column;

        public string MPiview_column
        {
            get { return mPiview_column; }
            set { mPiview_column = value; }
        }

        bool mRelative_path;

        public bool MRelative_path
        {
            get { return mRelative_path; }
            set { mRelative_path = value; }
        }

        string mReport_font;

        public string MReport_font
        {
            get { return mReport_font; }
            set { mReport_font = value; }
        }

        string mReport_font_size;

        public string MReport_font_size
        {
            get { return mReport_font_size; }
            set { mReport_font_size = value; }
        }

        string mPrint_font;

        public string MPrint_font
        {
            get { return mPrint_font; }
            set { mPrint_font = value; }
        }

        string mPrint_font_size;

        public string MPrint_font_size
        {
            get { return mPrint_font_size; }
            set { mPrint_font_size = value; }
        }

        string mCode;

        public string MCode
        {
            get { return mCode; }
            set { mCode = value; }
        }

        string mRelive_path;

        public string MRelive_path
        {
            get { return mRelive_path; }
            set { mRelive_path = value; }
        }


        string mTrue_arges;

        public string MTrue_arges
        {
            get { return mTrue_arges; }
            set { mTrue_arges = value; }
        }


        string mReportToPiview;

        public string MReportToPiview
        {
            get { return mReportToPiview; }
            set { mReportToPiview = value; }
        }
        public Model_cfg()
        {
            this.MPiview_column = AccessHelper.IniReadValue("SERVER", "PIVIEW_COLUMNE", Environment.CurrentDirectory + @"\sysconfig.ini");

            if (string.IsNullOrEmpty(this.MPiview_column))
            {

                AccessHelper.IniWriteValue("SERVER", "PIVIEW_COLUMNE", "PATIENT_ID", Environment.CurrentDirectory + @"\sysconfig.ini");
                this.MPiview_column = "PATIENT_ID";
            }


            //PIVIEW数据库路径
            this.MDbpath = AccessHelper.IniReadValue("SERVER", "MDBPATH", Environment.CurrentDirectory + @"\sysconfig.ini");

            if (string.IsNullOrEmpty(this.MDbpath))
            {

                AccessHelper.IniWriteValue("SERVER", "MDBPATH", "", Environment.CurrentDirectory + @"\sysconfig.ini");
            }

            //report数据库路径
            this.MDbpath_report = AccessHelper.IniReadValue("SERVER", "MDBPATH_REPORT", Environment.CurrentDirectory + @"\sysconfig.ini");

            if (string.IsNullOrEmpty(this.MDbpath_report))
            {

                AccessHelper.IniWriteValue("SERVER", "MDBPATH_REPORT", "", Environment.CurrentDirectory + @"\sysconfig.ini");
            }


            //PIVIEW_PATH
            this.MPiview_path = AccessHelper.IniReadValue("SERVER", "PIVIEW_PATH", Environment.CurrentDirectory + @"\sysconfig.ini");

            if (string.IsNullOrEmpty(this.MPiview_path))
            {

                AccessHelper.IniWriteValue("SERVER", "PIVIEW_PATH", "", Environment.CurrentDirectory + @"\sysconfig.ini");
            }



            this.MPiview_arges_dbtype = AccessHelper.IniReadValue("SERVER", "PIVIEW_ARGES_DBTYPE", Environment.CurrentDirectory + @"\sysconfig.ini");

            if (string.IsNullOrEmpty(this.MPiview_arges_dbtype))
            {

                AccessHelper.IniWriteValue("SERVER", "PIVIEW_ARGES_DBTYPE", "0", Environment.CurrentDirectory + @"\sysconfig.ini");
                this.MPiview_arges_dbtype = "0";
            }



            this.MPiview_arges_maxnum = AccessHelper.IniReadValue("SERVER", "PIVIEW_ARGES_MAXNUM", Environment.CurrentDirectory + @"\sysconfig.ini");

            if (string.IsNullOrEmpty(this.MPiview_arges_maxnum))
            {

                AccessHelper.IniWriteValue("SERVER", "PIVIEW_ARGES_MAXNUM", "3", Environment.CurrentDirectory + @"\sysconfig.ini");
                this.MPiview_arges_maxnum = "3";
            }



            this.MPiview_arges_userid = AccessHelper.IniReadValue("SERVER", "PIVIEW_ARGES_USERID", Environment.CurrentDirectory + @"\sysconfig.ini");

            if (string.IsNullOrEmpty(this.MPiview_arges_userid))
            {

                AccessHelper.IniWriteValue("SERVER", "PIVIEW_ARGES_USERID", "", Environment.CurrentDirectory + @"\sysconfig.ini");
                this.MPiview_arges_userid = "Administrator";
            }



            this.MPiview_arges_userpwd = AccessHelper.IniReadValue("SERVER", "PIVIEW_ARGES_USEPWD", Environment.CurrentDirectory + @"\sysconfig.ini");

            if (string.IsNullOrEmpty(this.MPiview_arges_userid))
            {

                AccessHelper.IniWriteValue("SERVER", "PIVIEW_ARGES_USEPWD", "", Environment.CurrentDirectory + @"\sysconfig.ini");
                this.MPiview_arges_userid = "";
            }


            this.MPiview_arges = AccessHelper.IniReadValue("SERVER", "PIVIEW_ARGES", Environment.CurrentDirectory + @"\sysconfig.ini");

            if (string.IsNullOrEmpty(this.MPiview_arges))
            {

                AccessHelper.IniWriteValue("SERVER", "PIVIEW_ARGES", "", Environment.CurrentDirectory + @"\sysconfig.ini");
                this.MPiview_arges = "*+|+*+*+*+*+*+*+*+*+";
            }



            this.MPrint_font = AccessHelper.IniReadValue("SERVER", "PRINT_FONT", Environment.CurrentDirectory + @"\sysconfig.ini");

            if (string.IsNullOrEmpty(this.MPrint_font))
            {

                AccessHelper.IniWriteValue("SERVER", "PRINT_FONT", "宋体", Environment.CurrentDirectory + @"\sysconfig.ini");
                this.MPrint_font = "宋体";
            }


            this.MPrint_font_size = AccessHelper.IniReadValue("SERVER", "PRINT_FONT_SIZE", Environment.CurrentDirectory + @"\sysconfig.ini");

            if (string.IsNullOrEmpty(this.MPrint_font_size))
            {

                AccessHelper.IniWriteValue("SERVER", "PRINT_FONT_SIZE", "12", Environment.CurrentDirectory + @"\sysconfig.ini");
                this.MPrint_font = "12";
            }

            this.MReport_font = AccessHelper.IniReadValue("SERVER", "REPORT_FONT", Environment.CurrentDirectory + @"\sysconfig.ini");

            if (string.IsNullOrEmpty(this.MReport_font))
            {

                AccessHelper.IniWriteValue("SERVER", "REPORT_FONT", "宋体", Environment.CurrentDirectory + @"\sysconfig.ini");
                this.MReport_font = "宋体";
            }



            this.MReport_font_size = AccessHelper.IniReadValue("SERVER", "REPORT_FONT_SIZE", Environment.CurrentDirectory + @"\sysconfig.ini");

            if (string.IsNullOrEmpty(this.MReport_font_size))
            {

                AccessHelper.IniWriteValue("SERVER", "REPORT_FONT_SIZE", "12", Environment.CurrentDirectory + @"\sysconfig.ini");
                this.MPrint_font = "12";
            }


            this.MCode = AccessHelper.IniReadValue("SERVER", "CODE", Environment.CurrentDirectory + @"\sysconfig.ini");

            if (string.IsNullOrEmpty(this.MReport_font_size))
            {

                AccessHelper.IniWriteValue("SERVER", "CODE", "", Environment.CurrentDirectory + @"\sysconfig.ini");

            }

            this.MRelive_path = AccessHelper.IniReadValue("SERVER", "RELATE_PATH", Environment.CurrentDirectory + @"\sysconfig.ini");

            if (string.IsNullOrEmpty(this.MRelive_path))
            {

                AccessHelper.IniWriteValue("SERVER", "RELATE_PATH", "", Environment.CurrentDirectory + @"\sysconfig.ini");

            }

            this.mReportToPiview = AccessHelper.IniReadValue("SERVER", "REPORTTOPIVIEW", Environment.CurrentDirectory + @"\sysconfig.ini");

            if (string.IsNullOrEmpty(this.mReportToPiview))
            {

                AccessHelper.IniWriteValue("SERVER", "REPORTTOPIVIEW", "", Environment.CurrentDirectory + @"\sysconfig.ini");

            }
            //string mxx = 
            //byte[] byteArray = System.Text.Encoding.ASCII.GetBytes(mxx);
            //string mxxxx = System.Text.Encoding.ASCII.GetString(byteArray);
            this.MTrue_arges = " /Open =" + this.MPiview_arges_dbtype + "+" + this.MPiview_arges_maxnum + "+" + this.MPiview_arges_userid + "+" + this.MPiview_arges_userpwd + this.MPiview_arges;
            ;
        }

        public void f_save_ini(string PIVIEW_COLUMNE, string RELATE_PATH, string REPORT_FONT_SIZE, string REPORT_FONT, string PRINT_FONT_SIZE
            , string PRINT_FONT, string PIVIEW_ARGES, string PIVIEW_ARGES_USEID, string PIVIEW_ARGES_DBTYPE, string PIVIEW_ARGES_USEPWD, string PIVIEW_ARGES_MAXNUM,
            string MDBPATH, string MDBPATH_REPORT, string PIVIEW_PATH)
        {
            AccessHelper.IniWriteValue("SERVER", "PIVIEW_COLUMNE", PIVIEW_COLUMNE, Environment.CurrentDirectory + @"\sysconfig.ini");
            AccessHelper.IniWriteValue("SERVER", "RELATE_PATH", RELATE_PATH, Environment.CurrentDirectory + @"\sysconfig.ini");
            AccessHelper.IniWriteValue("SERVER", "REPORT_FONT_SIZE", REPORT_FONT_SIZE, Environment.CurrentDirectory + @"\sysconfig.ini");
            AccessHelper.IniWriteValue("SERVER", "REPORT_FONT", REPORT_FONT, Environment.CurrentDirectory + @"\sysconfig.ini");
            AccessHelper.IniWriteValue("SERVER", "PRINT_FONT_SIZE", PRINT_FONT_SIZE, Environment.CurrentDirectory + @"\sysconfig.ini");
            AccessHelper.IniWriteValue("SERVER", "PRINT_FONT", PRINT_FONT, Environment.CurrentDirectory + @"\sysconfig.ini");
            AccessHelper.IniWriteValue("SERVER", "PIVIEW_ARGES", PIVIEW_ARGES, Environment.CurrentDirectory + @"\sysconfig.ini");
            AccessHelper.IniWriteValue("SERVER", "PIVIEW_ARGES_USERID", PIVIEW_ARGES_USEID, Environment.CurrentDirectory + @"\sysconfig.ini");
            AccessHelper.IniWriteValue("SERVER", "PIVIEW_ARGES_DBTYPE", PIVIEW_ARGES_DBTYPE, Environment.CurrentDirectory + @"\sysconfig.ini");
            AccessHelper.IniWriteValue("SERVER", "PIVIEW_ARGES_USEPWD", PIVIEW_ARGES_USEPWD, Environment.CurrentDirectory + @"\sysconfig.ini");
            AccessHelper.IniWriteValue("SERVER", "PIVIEW_ARGES_MAXNUM", PIVIEW_ARGES_MAXNUM, Environment.CurrentDirectory + @"\sysconfig.ini");
            AccessHelper.IniWriteValue("SERVER", "MDBPATH", MDBPATH, Environment.CurrentDirectory + @"\sysconfig.ini");
            AccessHelper.IniWriteValue("SERVER", "MDBPATH_REPORT", MDBPATH_REPORT, Environment.CurrentDirectory + @"\sysconfig.ini");
            AccessHelper.IniWriteValue("SERVER", "PIVIEW_PATH", PIVIEW_PATH, Environment.CurrentDirectory + @"\sysconfig.ini");

        }

        public void f_save_ini(Model_cfg pthis)
        {
            AccessHelper.IniWriteValue("SERVER", "PIVIEW_COLUMNE", pthis.MPiview_column, Environment.CurrentDirectory + @"\sysconfig.ini");
            AccessHelper.IniWriteValue("SERVER", "RELATE_PATH", pthis.MRelative_path == true ? "1" : "0", Environment.CurrentDirectory + @"\sysconfig.ini");
            AccessHelper.IniWriteValue("SERVER", "REPORT_FONT_SIZE", pthis.mReport_font_size, Environment.CurrentDirectory + @"\sysconfig.ini");
            AccessHelper.IniWriteValue("SERVER", "REPORT_FONT", pthis.MReport_font, Environment.CurrentDirectory + @"\sysconfig.ini");
            AccessHelper.IniWriteValue("SERVER", "PRINT_FONT_SIZE", pthis.MPrint_font_size, Environment.CurrentDirectory + @"\sysconfig.ini");
            AccessHelper.IniWriteValue("SERVER", "PRINT_FONT", pthis.MPrint_font, Environment.CurrentDirectory + @"\sysconfig.ini");
            AccessHelper.IniWriteValue("SERVER", "PIVIEW_ARGES", pthis.MPiview_arges, Environment.CurrentDirectory + @"\sysconfig.ini");
            AccessHelper.IniWriteValue("SERVER", "PIVIEW_ARGES_USEID", pthis.MPiview_arges_userid, Environment.CurrentDirectory + @"\sysconfig.ini");
            AccessHelper.IniWriteValue("SERVER", "PIVIEW_ARGES_DBTYPE", pthis.MPiview_arges_dbtype, Environment.CurrentDirectory + @"\sysconfig.ini");
            AccessHelper.IniWriteValue("SERVER", "PIVIEW_ARGES_USEPWD", pthis.MPiview_arges_userpwd, Environment.CurrentDirectory + @"\sysconfig.ini");
            AccessHelper.IniWriteValue("SERVER", "PIVIEW_ARGES_MAXNUM", pthis.MPiview_arges_maxnum, Environment.CurrentDirectory + @"\sysconfig.ini");
            AccessHelper.IniWriteValue("SERVER", "MDBPATH", pthis.MDbpath, Environment.CurrentDirectory + @"\sysconfig.ini");
            AccessHelper.IniWriteValue("SERVER", "MDBPATH_REPORT", pthis.MDbpath_report, Environment.CurrentDirectory + @"\sysconfig.ini");
            AccessHelper.IniWriteValue("SERVER", "PIVIEW_PATH", pthis.mPiview_path, Environment.CurrentDirectory + @"\sysconfig.ini");
            AccessHelper.IniWriteValue("SERVER", "REPORTTOPIVIEW", pthis.mReportToPiview, Environment.CurrentDirectory + @"\sysconfig.ini");
        }
    }
}
